﻿using System;
using System.Reflection;

namespace JinianNet.JNCms.Data
{
    public partial class DataAccess
    {
        private static string AssemblyPath;
        private static object CreateObject(string classNamespace)
        {
            string key = string.Concat("Cache_DALFactory_JNCms", classNamespace);
            object dal = JinianNet.Web.Cache.Create(Web.Cache.CacheMode.Memory).Get(key);
            if (dal == null)
            {
                if (string.IsNullOrEmpty(AssemblyPath))
                {
                    AssemblyPath = System.Configuration.ConfigurationManager.AppSettings["DataAssembly"];
                }
                dal = Assembly.Load(AssemblyPath).CreateInstance(string.Concat(AssemblyPath, classNamespace));
                JinianNet.Web.Cache.Create(Web.Cache.CacheMode.Memory)[key] = dal;
            }
            return dal;
        }

        private static object CreateObject<T>(string classNamespace)
        {
            return (T)CreateObject(classNamespace);
        }
    }
}
